package com.common.valid;



import com.common.Constants;
import com.common.valid.annotation.Password;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class PasswordValidator implements ConstraintValidator<Password,String> {
    private static final Pattern PASSWORD_PATTERN = Pattern.compile(Constants.VALID_PASSWORD_PATTERN);
    @Override
    public boolean isValid(String value, ConstraintValidatorContext context) {
        Matcher matcher = PASSWORD_PATTERN.matcher(value);
        return matcher.matches();
    }
}
